import router from './router'

const whiteList = ['/login'] // 无需令牌登录

router.beforeEach((to, from, next) => {
  // 判断如果不在登录页 修改标签title
  if (to.path !== '/login') {
    document.title = 'Amazon.ca Seller Profile: fryyoung'
  }
  const hasToken = sessionStorage.getItem('token')
  if (hasToken) {
    if (to.path === '/login') {
      next('/')
    }
    next()
  } else {
    if (whiteList.includes(to.path)) {
      next()
    } else {
      document.title = '亚马逊 登录'
      next('/login')
    }
  }
})
